package org.minos.edit.view.components
{
	import flash.events.Event;
	import org.aswing.ASColor;
	import org.aswing.BorderLayout;
	import org.aswing.Box;
	import org.aswing.Component;
	import org.aswing.ext.Form;
	import org.aswing.ext.FormRow;
	import org.aswing.GridLayout;
	import org.aswing.JButton;
	import org.aswing.JLabel;
	import org.aswing.JPanel;
	import org.aswing.JTextField;
	import org.aswing.SoftBoxLayout;
	import org.ichow.utils.StringUtil;
	import org.minos.edit.view.components.interfaces.IFile;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class InfoPane extends JPanel implements IFile
	{
		private var nameTf : JTextField;
		private var pathBtn : JButton;
		private var musicBtn : JButton;
		
		private var form : Form;
		private var pathTf : JLabel;
		private var musicTf : JLabel;
		
		public function InfoPane()
		{
			super();
			init();
		}
		
		/**
		 * 初始化界面
		 */
		private function init() : void
		{
			
			setLayout( new BorderLayout() );
			setOpaque( true );
			
			nameTf = new JTextField( "" , 12 );
			pathBtn = new JButton( "设置根目录" );
			pathTf = new JLabel( "" , null , JLabel.LEFT );
			musicBtn = new JButton( "浏览" );
			musicTf = new JLabel( "*.mp3" , null , JLabel.LEFT );
			
			form = new Form();
			append( form , BorderLayout.CENTER );
			form.setVGap( 2 );
			
			addLabelRow( nameTf , "课程名称: " );
			addLabelRow( pathBtn , "课程路径: " , pathTf );
			addLabelRow( musicBtn , "背景音乐: " , musicTf );
		
		}
		
		/**
		 * 添加列
		 * @param	c
		 * @param	text
		 * @param	tip
		 */
		private function addLabelRow( c : Component , text : String , tip : * = null ) : void
		{
			var label : JLabel = new JLabel( text , null , JLabel.LEFT );
			if ( tip != null && tip is String )
				tip = new JLabel( tip , null , JLabel.LEFT );
			else if ( tip != null && tip is JLabel )
				tip.setForeground( ASColor.GRAY );
			
			form.addRow( label , c , tip );
		}
		
		// ----- Get Components ----- //
		
		/**
		 *
		 * @return
		 */
		public function getNameTf() : JTextField
		{
			return nameTf;
		}
		
		public function getPathBtn() : JButton
		{
			return pathBtn;
		}
		
		public function getPathTf() : JLabel
		{
			return pathTf;
		}
		
		public function getMusicBtn() : JButton
		{
			return musicBtn;
		}
		
		public function getMusicTf() : JLabel
		{
			return musicTf;
		}
		
		/* INTERFACE org.minos.edit.view.components.interfaces.IFile */
		
		public function clear() : void
		{
			pathTf.setText( "" );
			musicTf.setText( "" );
			nameTf.setText( "" );
		}
		
		public function getXML() : XML
		{
			var xml : XML =       <config />;
			xml.@key = StringUtil.randomString( 10 );
			xml.@name = nameTf.getText();
			xml.@classPath = pathTf.getText();
			xml.@backGroundMusic = musicTf.getText();
			return xml;
		}
		
		public function setXML( xml : Object ) : void
		{
			var _xml : XML = new XML( xml );
			nameTf.setText( _xml.@name );
			pathTf.setText( _xml.@classPath );
			musicTf.setText( _xml.@backGroundMusic );
		}
	
	}

}